using Magiq.Update;

namespace Magiq.Sql {
    public class MagiqToSqlUpdateProvider : MagiqToSqlOperationsProvider, IUpdateStrategy {
        private readonly IDependentTablesUpdateStrategy dependentTablesUpdateStrategy;

        public MagiqToSqlUpdateProvider(IDependentTablesUpdateStrategy dependentTablesUpdateStrategy) {
            this.dependentTablesUpdateStrategy = dependentTablesUpdateStrategy;
        }

        #region IUpdateStrategy Members

        public int Execute<T>(IQueryableUpdate<T> update) where T : class {
            var dataContext = update.Where.DataContext();

            var massUpdate = new MassUpdate<T>(update, dataContext, dependentTablesUpdateStrategy);
            return massUpdate.Execute();
        }

        #endregion
    }
}